const { contextBridge, ipcRenderer } = require("electron")

/**
 * The preload script runs before. It has access to web APIs
 * as well as Electron's renderer process modules and some
 * polyfilled Node.js functions.
 *
 * https://www.electronjs.org/docs/latest/tutorial/sandbox
 */
window.addEventListener('DOMContentLoaded', () => {
  const replaceText = (selector, text) => {
    const element = document.getElementById(selector)
    if (element) element.innerText = text
  }

  for (const type of ['chrome', 'node', 'electron']) {
    replaceText(`${type}-version`, process.versions[type])
  }
})

// 向vue项目暴漏一些属性和方法
contextBridge.exposeInMainWorld('versions',{
//   // 最小化/最小化到系统托盘
  minimize(val){
    ipcRenderer.send("minimize",val)
  },
  // 窗口最大化
  windowStatus(){
    ipcRenderer.send("windowStatus")
  },
  //  关闭当前窗口
  closeWin(){
    ipcRenderer.send("closeWin")
  },
  // 处理拖拽窗口事件
  handleDragWindow(offsetX,offsetY){
    ipcRenderer.send('drag-window',{offsetX,offsetY})
  },
  // windowMoveRequest(){
  //   ipcRenderer.send("window-move-request")
  // },
})
